#ifndef X11EVENTFILTER_H
#define X11EVENTFILTER_H

#include <QObject>
#include <QThread>
#include <QDebug>

#include <X11/Xlib.h>
#include <X11/extensions/record.h>

// Virtual button codes that are not defined by X11.
#define Button1			1
#define Button2			2
#define Button3			3
#define WheelUp			4
#define WheelDown		5
#define WheelLeft		6
#define WheelRight		7
#define XButton1		8
#define XButton2		9

class X11EventFilter : public QThread
{
    Q_OBJECT
public:
    explicit X11EventFilter(QObject *parent = nullptr);

    void setWindow(unsigned long win);

signals:
    void buttonPress(unsigned long win, int x, int y);
    void buttonDrag(unsigned long win, int x, int y);
    void buttonRelease(unsigned long win, int x, int y);
    void keyPress(unsigned long win, int code);
    void keyRelease(unsigned long win, int code);

protected:
    bool filterWheelEvent(int detail);
    static void callback(XPointer trash, XRecordInterceptData* data);
    void handleRecordEvent(XRecordInterceptData *);
    void run() override;

private:
    bool isPress;
    unsigned long m_win;

public slots:


};

#endif // X11EVENTFILTER_H
